package net.tcp;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

/**
 * 	客户端
 * @author Administrator
 *
 */
public class TCPClient {

	public static void main(String[] args) throws UnknownHostException, IOException {
		System.out.println("正在链接服务器。。。。");
		// 链接服务器
		Socket socket = new Socket("localhost", 8888);
		System.out.println("服务器已链接");
		
		// 循环发送数据
		OutputStream out = socket.getOutputStream();
		Scanner scanner = new Scanner(System.in);
		while(true) {
			String content = scanner.nextLine();
			// 当content为bye的时候结束
			if("bye".equals(content)) {
				break;
			}
			
			// 循环去写数据
			out.write(content.getBytes());
		}
		
		// 关闭资源
		out.close();
		scanner.close();
		socket.close();
		
	}
	
	
	
}
